﻿using LVYAN.Model;
using LVYAN.Model.AutoMation;
using LVYAN.Utils;
using System;

namespace LVYAN.Service.AIAPI
{
    /// <summary>
    /// 
    /// </summary>
    public class MessageManage : BaseAPI
    {
        /// <summary>
        /// 记录聊天记录
        /// </summary>
        /// <returns></returns>
        public static void Send(SENDDATA Model)
        {
            var content = JsonService.ToString(Model);
            new LoggerService().ResponseMsgDebug("消息管理", "记录聊天记录发送消息", content);
            var result = new RequestService().PostJson($"{AIAPI}api/aichat/send", content);
            new LoggerService().ResponseMsgDebug("消息管理", "记录聊天记录接受消息", result);
        }

        /// <summary>
        /// 记录聊天记录
        /// </summary>
        /// <returns></returns>
        public static void Send(RobotModel Robot, RobotRobotOther RobotOther, bool IsQun, int RoomCount, string Message, string RoomName, string RoomAvatar, string ImgUrl, string MessagesType,string HistoryId, bool IsForward)
        {
            var SendData = new SENDDATA
            {
                HistoryId= HistoryId,
                Message = Message,
                Messages = Message,
                MsgDate = Convert.ToDateTime(DateTime.Now.ToString($"yyyy-MM-dd HH:mm:00")),
                NickName = Robot.RobotName,
                RoomNickName = Robot.RobotName,
                RobotName = Robot.RobotName,
                RobotCode = Robot.RobotCode,
                NickAvatar = Robot.RobotAvatar,
                RoomNameOrg = RoomName,
                RoomName = RoomName,
                RoomCount = RoomCount,
                RoomAvatar = RoomAvatar,
                TenantID = RobotOther.TenantID,
                MacIP = WinInfo.GetIP(),
                MacAddress = WinInfo.GetMacAddress(),
                MacName = WinInfo.GetHostName(),
                RoomType = IsQun ? "群" : "个人",
                ImgUrl = ImgUrl,
                MessageType = MessagesType,
                IsForward = IsForward,
            };
            SendData.RequestId = new SignService().SignMD5($"{SendData.Message}{SendData.Messages}{SendData.MsgDate.ToString("yyyyMMddHH")}{SendData.RobotCode}{SendData.RoomName}{SendData.NickName}{SendData.RoomNickName}");
            //记录最后一次聊天
            Send(SendData);
        }


    }
}
